local aocai = fk.CreateSkill {

  name = "joy__aocai",

  tags = {  },

}



aocai:addEffect("viewas", {
  name = "joy__aocai",
  pattern = ".|.|.|.|.|basic",
  anim_type = "special",
  expand_pile = function(self,player) return player:getTableMark( "joy__aocai") end,
  prompt = function()
    return "#joy__aocai"
  end,
  card_filter = function(self, player, to_select, selected)
    if #selected == 0 and table.contains(player:getTableMark(  "joy__aocai"), to_select) then
      local card = Fk:getCardById(to_select)
      if card.type == Card.TypeBasic then
        if Fk.currentResponsePattern == nil then
          return player:canUse(card) and not player:prohibitUse(card)
        else
          return Exppattern:Parse(Fk.currentResponsePattern):match(card)
        end
      end
    end
  end,
  view_as = function(self, player,cards)
    if #cards ~= 1 then return end
    return Fk:getCardById(cards[1])
  end,
  enabled_at_play = function(self, player)
    return false
  end,
  enabled_at_response = function(self, player, response)
    return player.phase == Player.NotActive
  end,
})

aocai:addEffect(fk.AskForCardUse, {
  refresh_events = {fk.AskForCardUse, fk.AskForCardResponse},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(aocai.name) and player ~= player.room.current
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local n = player:isKongcheng() and 4 or 3
    local ids = {}
    for i = 1, n, 1 do
      if i > #room.draw_pile then break end
      table.insert(ids, room.draw_pile[i])
    end
    player.room:setPlayerMark(player, "joy__aocai", ids)
  end,
})
aocai:addEffect(fk.AskForCardResponse, {
  refresh_events = {fk.AskForCardUse, fk.AskForCardResponse},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(aocai.name) and player ~= player.room.current
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local n = player:isKongcheng() and 4 or 3
    local ids = {}
    for i = 1, n, 1 do
      if i > #room.draw_pile then break end
      table.insert(ids, room.draw_pile[i])
    end
    player.room:setPlayerMark(player, "joy__aocai", ids)
  end,
})

return aocai